package com.yc.cloud.cloudorder.web;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
public class OrderAction {
    @RequestMapping("order")
    public String order(HttpServletRequest request){
        int port=request.getServerPort();
        return "order:"+port;
    }

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping("order-user")
    public String user(){
        String url="http://127.0.0.1:8001/user";
        String object=restTemplate.getForObject(url,String.class);
        return "order: "+object;
    }

    @RequestMapping("order-index")
    public String index(){
        String url="http://127.0.0.1:80/index";
        String object=restTemplate.getForObject(url,String.class);
        return "order: "+object;
    }

    @RequestMapping("order-user1")
    public String user1(){
        String url="http://cloud-user/user";
        String object=restTemplate.getForObject(url,String.class);
        return "order: "+object;
    }

    @RequestMapping("order-index1")
    public String index1(){
        String url="http://cloud-index/index";
        String object=restTemplate.getForObject(url,String.class);
        return "order: "+object;
    }
}
